import {
    GETDATA,
    L,
    getField
} from '../utils/R'

export default {
    namespace: 'rightBottom',
    state: {},
    subscriptions: {
        setup({
            dispatch,
            history
        }) {
            history.listen(({
                pathname
            }) => {
                if (pathname == '/two') {
                    dispatch({
                        type: 'getDatas'
                    })
                }
            })
        }
    },
    effects: {
        * getDatas({
            params
        }, {
            call,
            put
        }) {
            let {
                data
            } = yield call(GETDATA, L)

            let {
                pc,
                pcRate,
                phone,
                phoneRate
            } = data[0]

            let payload = [{
                    value: pc,
                    name: '电脑'
                },
                {
                    value: phone,
                    name: '手机'
                }
            ]

            yield put({
                type: 'setData',
                payload
            })
        }
    },
    reducers: {
        setData(state, action) {
            return action.payload
        }
    }
}